# -- coding: utf-8 --
import configparser


# 创建读取ini文件工具类
class ReadIni(object):

    def __init__(self, file_name=None, node=None):
        # 初始化登录参数
        if file_name is None:
            self.file_name = "../config/login_element.ini"
        else:
            self.file_name = file_name
        if node is None:
            self.node = 'DEFAULT'
        else:
            self.node = node
        self.cf = self.load_ini()

    def load_ini(self):
        cf = configparser.ConfigParser()
        cf.read(self.file_name,encoding='utf-8')
        return cf

    # 获取ini文件中对应的key的值
    def get_value(self, key):
        try:
            data = self.cf.get(self.node, key)
            return data
        except configparser.NoSectionError as e:
            raise e


if __name__ == '__main__':
    read_ini = ReadIni(r"D:\Program Files\PycharmProject\autocase\tools\example.ini","DEFAULT")
    print(read_ini.get_value('serveraliveinterval'))